/*
    密码框的显示与隐藏
*/
let eye = document.getElementById("i3");
let flag = 0;
eye.onclick = function () {
    let password = document.getElementById("password")
    if (flag == 0) {
        password.type = "text";
        eye.innerHTML = "&#xe658;";
        flag = 1;
    } else {
        password.type = "password";
        eye.innerHTML = "&#xe63a;";
        flag = 0
    }
}


/*
    验证账号密码
*/
let commit = document.getElementById("commit");
commit.onsubmit = function (e) {
    e.preventDefault();
    let username = document.getElementById("username").value;
    let password = document.getElementById("password").value;
    if (!(/^\w{6,16}$/i.test(username) && /^\w{6,16}$/i.test(password))) {
        return alert("请输入正确的账号或密码");
    }
    Ajax({
        type: "POST",
        url: "http://localhost/Dorm%20Management/server/login.php",
        data: { username, password },
        success(data) {
            console.log(data);
            sessionStorage.setItem("userInfo", data);
           data = JSON.parse(data);
            console.log(data);
            if (data) {
                sessionStorage.setItem("login", data.power)
                location.href = "http://localhost/Dorm%20Management/html/home.html"
            } else {
                alert("账号或密码错误");
                location.reload();
            }
        }
    })
}



